#include "HistogramWidget.h"
#include <QPainter>


HistogramWidget::HistogramWidget(QWidget *parent) :
    QWidget(parent),
    m_color(255),
    m_scale(1.0)
{

}

void HistogramWidget::setColor(QColor color)
{
    m_color = color;

    update();
}

void HistogramWidget::setScale(double scale)
{
    if (scale < 0)
    {
        scale = 0;
    }

    if (scale > 1.0)
    {
        scale = 1.0;
    }

    m_scale = scale;

    update();
}

void HistogramWidget::paintEvent(QPaintEvent* /*event*/)
{
    QPainter painter(this);
    QRect rc = rect();
	rc.adjust(4, 4, -4, -4);

	int top = rc.bottom() - rc.height() * m_scale;
	rc.setTop(top);

	QPen pen(m_color);
	pen.setWidth(4);
    painter.setPen(pen);

    painter.drawRect(rc);
}
